package hello;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class HelloMIDlet extends MIDlet implements CommandListener {

    private Command exitCommand; // The exit command
    private Display display;     // The display for this MIDlet
    private MyGameCanvas canvas;

    public boolean running;
            
    public HelloMIDlet() {
        display = Display.getDisplay(this);
        exitCommand = new Command("Exit", Command.EXIT, 0);
    }

    public void bumpAlert( String msg )
    {
        try
        {
            Alert f = new Alert( msg );
            if( f != null)
                display.setCurrent( f );
        }
        catch( Exception e )
        {
            Alert f = new Alert( e.getMessage() );
            display.setCurrent(f);
        }
    }

    MyGameCanvas getCanvas()
    {
        return canvas;
    }
    
    public void startApp() {
        running = true;
        canvas = new MyGameCanvas( this );
        
        canvas.addCommand( exitCommand );
        canvas.setCommandListener(this);
        canvas.start();
        canvas.setFullScreenMode( true );
        display.setCurrent(canvas);

        BTProcessor processor = BTProcessor.GetInst();
        processor.setParent(this);
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }

    public void commandAction(Command c, Displayable s) {
        if (c == exitCommand) {            
            destroyApp(false);
            notifyDestroyed();
            running = false;
        } 
    }

}
